$(function(){
    $('.goods-star-choose').rating({
        messages:[
            '<span class="evaluation-describe">（请您选择评价）</span>',
            '<span class="evaluation-score">1分</span><span class="evaluation-describe">（这个商品糟透了）</span>',
            '<span class="evaluation-score">2分</span><span class="evaluation-describe">（只能算是勉勉强强）</span>',
            '<span class="evaluation-score">3分</span><span class="evaluation-describe">（一般般，没什么出彩的地方）</span>',
            '<span class="evaluation-score">4分</span><span class="evaluation-describe">（总体质量不错，商品描述符合）</span>',
            '<span class="evaluation-score">5分</span><span class="evaluation-describe">（商品各方面做的都太棒了）</span>'
        ],
        showLabel: true,
        inline: true
    }).change(function(){
        $(this).closest("p").find("input").val($(this).rating('val'));
    });
    $(".goods-evaluation-box .submit-eva").click(function(){
        var id=$(this).closest(".goods-evaluation-box").attr("data-id");
        evaluationSwitch(id,false);
    });
    $(".order-content .evalution-operation a").click(function(){
        var id=$(this).closest(".order-content").attr("data-id");
        evaluationSwitch(id,true);
    });

    function evaluationSwitch(id,state){
        if(typeof state=='undefined'){
            $(".goods-evaluation-box[data-id="+id+"]").toggle();
        }else{
            if(state){
                $(".goods-evaluation-box[data-id="+id+"]").show();
            }else{
                $(".goods-evaluation-box[data-id="+id+"]").hide();
            }
        }
    }

    (function(){
        function easyUploader(box){
            var config = {
                $button:box.find('.add-goods-photo'),
                $picArea:box.find(''),
                $uploader:box.find('.uploader'),
                $viewImgTpl:box.find('.goods-photo-tpl').remove(),
                $inputTpl:box.find(".uploader-input").remove(),
                imgType:'',
                insertPlace:box.find(".hidden-insert"),
                insertClass:"insert-ie-loader"
            };
            var loader = BMXimg.init(config);
            loader.then(function(d,$e){
                console.log($e);
                if(d.state==200){
                    var newImg = config.$viewImgTpl.clone().attr('src', d.data['url']);
                    var newInput = config.$inputTpl.clone().val(d.data.photoId)
                    //alert(d.data.photoId)
                    newInput.attr('name', newInput.attr('name')+"["+box.find(".uploader-input").length+"]");
                    config.$button.after(newImg).after(newInput);

                    //console.log($e);
                    //console.log(config.$viewImgTpl,d.data['url'])
                    //config.$viewImgTpl.attr('src', d.data['url']);
                    //config.$inputTpl.val(d.data.photoId);
                }else{
                    alert('上传失败')
                }
            });
        }
        window.easyUploader = easyUploader;
        console.log(easyUploader)
    })()
});